<!-- ! 自己封装的分页 -->
<template>
  <el-pagination
    class="Pagination"
    :current-page="props.currentPage"
    :page-size="props.pageSize"
    :page-sizes="props.pageSizes"
    :layout="props.layout"
    :total="props.total"
    :background="props.background"
    @size-change="handleSizeChange"
    @current-change="handleCurrentChange"
  >
  </el-pagination>
</template>

<script setup lang="ts">
interface Props {
  currentPage: number; // 当前页
  pageSize: number; // 每页显示多少条
  total: number; // 总条数据
  pageSizes?: number[]; // 设置每页多少条数据
  layout?: string; // 布局
  background?: boolean; // 背景
  config?: {};
}
interface Emit {
  (event: "update:currentPage", v: number): void;
  (event: "update:pageSize", v: number): void;
  (event: "onPagination", page: number, size: number): void;
}

// const props = withDefaults(defineProps<Props>(), {});
const props = withDefaults(defineProps<Props>(), {
  layout: "total, sizes, prev, pager, next, jumper",
  background: true,
});
const emit = defineEmits<Emit>();

const handleSizeChange = (num: number) => {
  emit("update:pageSize", num);
  emit("onPagination", num, props.pageSize);
};
const handleCurrentChange = (num: number) => {
  emit("update:currentPage", num);
  emit("onPagination", num, props.pageSize);
};
</script>

<style scoped lang="less">
.Pagination {
  :deep(.el-pagination__total) {
    color: #fff;
  }
}
</style>
